<template>
  <view>
    <view class="list-container">
      <view class="item" v-if="entryType!='1' && entryType!='6'">
        <view class="top-label" @click="showBasicInfoShowFlag = !showBasicInfoShowFlag">
          <view>基本信息</view>
          <view v-if="showBasicInfoShowFlag">
            <uv-icon name="arrow-down" size="40rpx" color="#000000"></uv-icon>
          </view>
          <view v-else>
            <uv-icon name="arrow-right" size="40rpx" color="#000000"></uv-icon>
          </view>
        </view>
        <view class="info" v-if="showBasicInfoShowFlag">
          <!-- 学校、食堂信息 -->
          <view class="row" v-if="entryType !== '5'">
            <view class="title">学校名称:</view>
            <view class="con">{{ formData.schoolName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5'">
            <view class="title">校长姓名:</view>
            <view class="con">{{ formData.masterName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">所属地区:</view>
            <view class="con">{{ formData.addressAll||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">学校地区类型:</view>
            <view class="con">{{ formData.distinctTypeName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">详细地址:</view>
            <view class="con">{{ formData.address||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">学校办学类型:</view>
            <view class="con">{{ formData.doSchoolTypeName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5'">
            <view class="title">学校办学性质:</view>
            <view class="con">{{ formData.schoolPropertiesName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">学校供餐模式:</view>
            <view class="con" v-if="formData.params && formData.params.schoolType === '01' ">
              {{  formData.canteenFlag === 0 ? "自有食堂" : formData.canteenFlag === 2 ? "委托经营" : '--' }}
            </view>
            <view class="con" v-if="formData.params && formData.params.schoolType === '02'  && formData.serveFlag === 1">
              {{ formData.canteenFlag == 1 ? "外部供餐" : formData.canteenFlag == 0 ? "自有食堂" : '--'}}
            </view>
            <view v-else class="con">--</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">学校教师总人数:</view>
            <view class="con">{{ formData.teacherAmount||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">学校学生总人数:</view>
            <view class="con">{{ formData.studentAmount||"--" }}</view>
          </view>

          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">统一社会信用代码:</view>
            <view class="con">{{ formData.orgCode||"--" }}</view>
          </view>
          <view class="row" v-if="entryType !== '5' && entryType !== '3'">
            <view class="title">AI监控:</view>
            <view class="con">{{ formData.cameraFlag == 0 ? '否' : '是' }}</view>
          </view>
          <!-- 食堂信息 -->
          <view class="row" v-if="entryType === '3'">
            <view class="title">供餐模式:</view>
            <view class="con">{{ formData.serveFlag==1 ? (formData.canteenFlag == 1 ? '外部供餐' : '自有食堂') : '否' }}</view>
          </view>
          <view class="row" v-if="entryType === '3'">
            <view class="title">食堂名称:</view>
            <view class="con">{{ formData.canteenName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType === '3'">
            <view class="title" style="width: 300rpx;">食安管理人员:</view>
            <view class="con">{{ formData.manager||"--" }}</view>
          </view>
          <!-- 配餐单位信息 -->
          <view class="row" v-if="entryType === '5'">
            <view class="title" style="width: 300rpx;">配餐单位名称:</view>
            <view class="con">{{ formData.caterName||"--" }}</view>
          </view>
          <view class="row" v-if="entryType === '5'">
            <view class="title" style="width: 300rpx;">负责人:</view>
            <view class="con">{{ formData.legalPerson||"--" }}</view>
          </view>
          <view class="row" v-if="entryType === '5'">
            <view class="title" style="width: 300rpx;">餐饮风险量化等级:</view>
            <view class="con">{{ formData.quantifyGradeName||"--" }}</view>
          </view>
        </view>
      </view>
    </view>
    <view class="item" v-if="entryType=='1'">
      <view class="info">
        <!-- 学校信息 -->
        <schoolInformation :schoolId="props.schoolId"></schoolInformation>
        <!-- 食堂信息 -->
        <canteenInformation :canteenId="props.canteenId"></canteenInformation>
        <!-- 从业人员 -->
        <employedInformation :canteenId="props.canteenId"></employedInformation>
        <!-- 库存食材 -->
        <foodInformation :canteenId="props.canteenId"></foodInformation>
      </view>
    </view>
    <view class="item" v-if="entryType=='6'">
      <view class="info">
        <!-- 配餐信息 -->
        <caterInformation :schoolId="props.schoolId"></caterInformation>
        <!-- 从业人员 -->
        <employedInformation :canteenId="props.schoolId"></employedInformation>
        <!-- 库存食材 -->
        <foodInformation :canteenId="props.schoolId"></foodInformation>
      </view>
    </view>
  </view>
</template>

<script setup>
  import schoolInformation from './schoolInformation.vue';
  import foodInformation from './foodInformation.vue';
  import employedInformation from './employedInformation.vue';
  import canteenInformation from './canteenInformation.vue';
  import caterInformation from './caterInformation.vue';
  import publicAPI from '@/api/law/public/public';
  import {reactive, ref, getCurrentInstance, defineProps} from "vue";

  let {proxy} = getCurrentInstance();
  let entryType = ref(uni.getStorageSync('entryType'));
  const props = defineProps({
    schoolId: {
      type: String,
      default: '',
      required: true
    },
    canteenId: {
      type: String,
      default: '',
      required: true
    },
  });
  let showBasicInfoShowFlag = ref(true)
  let schoolData = reactive({
    name: '',
    masterName: '',
    canteenFlag: '',
    schoolPropertiesName: '',
  });
  let canteenData = ref({
    name: '',
    manager: '',
    typeName: '',
  });
  // 初始化数据
  let initData = () => {
    if (entryType.value === '5') {
      getCaterInfo(props.schoolId);
    } else if (entryType.value === '3') {
      getCanteenInfo(props.canteenId);
    } else {
      getSchoolInfo(props.schoolId);
    }
  }
  onMounted(() => {
    if (entryType.value != "1" && entryType.value != "6") {
      initData();
    }
  });

  let schoolInfo = ref({});
  let canteenInfo = ref({});
  const formData = ref({});

  /** 获取学校信息 */
  function getSchoolInfo(e) {
    if (e) {
      proxy.http.post(publicAPI.schoolQuery(e)).then(res => {
        if (res.code === 0) {
          schoolInfo.value = res.data;
          formData.value = schoolInfo.value;
          formData.value.schoolName = schoolInfo.value.name;
          formData.value.canteenName = canteenInfo.value.name;
          console.log(123123123123,formData.value)
        } else {
          uni.showToast({title: res.msg, icon: 'none'});
        }
      })
    }
  }

  /** 获取食堂信息 */
  function getCanteenInfo(e) {
    proxy.http.get(publicAPI.canteenQuery(e)).then(res => {
      if (res.code === 0) {
        canteenInfo.value = res.data;
        getSchoolInfo(canteenInfo.value.schoolId);
      } else {
        uni.showToast({title: res.msg, icon: 'none'});
      }
    })
  }

  /** 获取配餐单位信息 */
  function getCaterInfo(e) {
    proxy.http.get(publicAPI.caterQuery(e)).then(res => {
      if (res.code === 0) {
        formData.value = res.data;
        formData.value.caterName = formData.value.name;
      } else {
        uni.showToast({title: res.msg, icon: 'none'});
      }
    })
  }
</script>

<style lang="scss" scoped>
  //公用样式文件
  @import "@/static/css/packageBase/smain.scss";
  @import "@/static/css/packageBase/lmain.scss";
  //日常检查样式
  @import "@/static/css/dailycheck/dailycheck.scss";
  @import "@/static/css/dailycheck/viewIndex.scss";
  .title {
    width: 35vw!important;
  }
</style>
